<template>
  <div>
    <p class="desc">选择能发起该审批的人员/部门，不选则默认开放给所有人</p>
    <el-button size="small" @click="selectOrg" :icon="Plus" type="primary" round>请选择</el-button>
    <org-items v-model="select" />
    <org-picker title="请选择可发起本审批的人员/部门" multiple ref="orgPicker" :selected="select" @ok="selected"/>
  </div>
</template>

<script>
import OrgPicker from '/@/views/setting/workflow/process/OrgPicker.vue'
import OrgItems from "/@/views/setting/workflow/process/OrgItems.vue";
import { Plus } from '@element-plus/icons-vue'
import { computed, reactive, ref, toRefs } from 'vue';
export default {
    name: 'RootConfig',
    components: { OrgPicker, OrgItems },
    props: {
        config: {
            type: Object,
            default: () => {
                return {}
            },
        },
    },
    setup(props) {
        const { config } = toRefs(props)
        const orgPicker = ref()
        const state = reactive({
            showOrgSelect: false,
        })
        const select = computed(() => {
            return config.value.assignedUser
        })
        const selectOrg = () => {
            orgPicker.value.show()
        }
        const selected = (select) => {
            select.value.length = 0
            select.forEach((val) => select.value.push(val))
        }
        const removeOrgItem = (index) => {
            select.value.splice(index, 1)
        }
        return {
            ...toRefs(state),
            Plus,
            select,
            selectOrg,
            selected,
            removeOrgItem,
            orgPicker
        }
    }
}
</script>

<style lang="scss" scoped>
.desc {
  font-size: small;
  color: #8c8c8c;
  padding: 13px 0;
}
.org-item {
  margin: 5px;
}
</style>